<template>
<div>
  <t-table rowKey="index" size="small" :data="data" :columns="columns" hover :pagination="pagination"
           :loading="dataLoading" :sort="sort" :hideSortTips="true" @sort-change="sortChange">
    <template #projectName="{ row }">
<!--      <t-link @click="nameClick(row)" hover="color" theme="primary">{{ row.projectName }}</t-link>-->
      {{ row.projectName }}
    </template>
    <template #standardProperty="{ row }">
      {{ row.standardProperty | filterByDict(dict.type.standard_property) }}
    </template>
    <template #systemName="{ row }">
      {{row.systemName || "-"}}
    </template>
    <template #formulateType="{ row }">
      {{ row.formulateType | filterByDict(dict.type.formulate_type) }}
    </template>
    <template #standardCategory="{ row }">
      {{ row.standardCategory | filterByDict(dict.type.standard_category) }}
    </template>
    <template #reviseNum="{ row }">
      {{ row.reviseNum || "-" }}
    </template>
    <template #draftUnitNames="{ row }">
        <t-tooltip :content="row.draftUnitNames">
          <p style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-overflow: ellipsis; overflow: hidden;">
            {{row.draftUnitNames || "-"}}
          </p>
        </t-tooltip>
      </template>
    <template #consistencyDegree="{ row }">
      {{row.consistencyDegree || "-"}}
    </template>
    <template #internationalStandardNum="{ row }">
      {{row.internationalStandardNum || "-"}}
    </template>
    <template #manageDeptId="{ row }">
      {{ row.manageDeptId | filterByTree(deptMenuOptions) }}
    </template>
    <template #completeDate="{ row }">
      {{row.completeDate|| "-"}}
    </template>
    <template #publishDate="{ row }">
      {{row.publishDate|| "-"}}
    </template>
    <template #implDate="{ row }">
      {{row.implDate|| "-"}}
    </template>
<!--    <template #localStandardStatus="{ row }">-->
<!--      <t-tag  @click="dialog.header=row.projectName;dialog.standardCategory=row.standardCategory;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.localStandardStatus, dict.type.local_standard_status)" variant="light">-->
<!--        {{ row.localStandardStatus | filterByDict(dict.type.local_standard_status) }}-->
<!--      </t-tag>-->
<!--    </template>-->
<!--    <template #op="{ row }">-->
<!--      <t-button size="small" @click="nameClick(row)" variant="text" class="t-button-link">-->
<!--        <t-icon name="info-circle" slot="icon"/>-->
<!--        详情-->
<!--      </t-button>-->
<!--    </template>-->
  </t-table>
  <standardDetailDialog  :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
  </standardDetailDialog>
  <approveList :header="dialog.header" :standardCategory="dialog.standardCategory" :obj-id="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approveList>
</div>
</template>

<script>
// import standardDetailDialog from "../../../bzh/standard/components/standard-detail-dialog.vue";
import approveList from "../../../bzh/approve/components/approve-list.vue";

export default {
  name: "bzh-list",
  dicts:["formulate_type","standard_property","standard_category","local_standard_status"],
  components:{
    // standardDetailDialog,
    standardDetailDialog: () => import('../../../bzh/standard/components/standard-detail-dialog.vue'),

    approveList
  },
  props:["deptId","idCard"],
  data() {
    return {
      dialog: {
        objId: null,
        header: "",
        open_detail: false,
        open_approve_list: false,
        standardCategory: '',
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: "",
        projectNum: '',
        localStandardStatus: '',
        formulateType: "",
        publicDateRange: [],
        standardProperty: '',
        standardCategory: '',
        draftUnitNames: '',
        draftPersonNames: '',
        startPublishDate: '',
        endPublishDate: '',
        deptId: this.deptId,
        idCard: this.idCard,
      },
      deptMenuOptions: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      sort: [],
      dataLoading: false,
      columns: [
        // {
        //   colKey: "projectNum",
        //   title: "标准编号",
        //   align: "center",
        //   width: 160,
        // },
        {
          colKey: "projectName",
          title: "标准名称",
          align: "center",
          width: 220
        },
        {
          colKey: "systemName",
          title: "标准体系",
          align: "center",
          width: 160,
        },
        {
          colKey: "standardProperty",
          title: "标准性质",
          align: "center",
          width: 100,
        },
        {
          colKey: "standardCategory",
          title: "标准类别",
          align: "center",
          width: 100,
        },
        {
          colKey: "formulateType",
          title: "制定或修订",
          align: "center",
          width: 120,
        },
        {
          colKey: "draftUnitNames",
          title: "主要起草单位",
          align: "center",
          width: 180,
          ellipsis: true,
        },
        {
          colKey: "completeDate",
          title: "完成时间",
          align: "center",
          width: 120,
          sorter: true,
        },
        // {
        //   colKey: "publishDate",
        //   title: "发布时间",
        //   align: "center",
        //   width: 120,
        //   sorter: true,
        // },
        // {
        //   colKey: "implDate",
        //   title: "实施时间",
        //   align: "center",
        //   width: 120,
        //   sorter: true,
        // },
        // {
        //   colKey: "localStandardStatus",
        //   title: "标准状态",
        //   align: "center",
        //   width: 180,
        //   fixed: 'right'
        // },
        // // {
        // //   colKey: "approveStatus",
        // //   title: "审批状态",
        // //   align: "center",
        // //   width: 160,
        // // },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center",
        //   width: 120,
        //   fixed: 'right'
        // },
      ],
      opinionVisible: true,
      data: [],

    }
  },
  async created() {
    await this.getDeptTreeSelect()
    this.getList()
  },
  methods:{
    getList(){
      if(this.deptId){
        this.dataLoading = true
        this.$api.bzh.standard.list(this.queryParams).then(response=>{
          this.pagination.total = response.total
          this.data = response.rows
          this.dataLoading = false
        }).catch(e=>{
          this.dataLoading = false
          this.$message.error(e.toString())
        })
      }else if(this.idCard){
        this.dataLoading = true
        this.$api.bzh.standard.myJoinList(this.queryParams).then(response=>{
          this.pagination.total = response.total
          this.data = response.rows
          this.dataLoading = false
        }).catch(e=>{
          this.dataLoading = false
          this.$message.error(e.toString())
        })
      }

    },
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
